﻿using System;
using System.Security.Cryptography;
using System.Text;

namespace Ycg.Security
{
    public static class MD5
    {
        /// <summary>
        /// MD5 encrypt, first use utf8 convert to byte, end convert byte to base64 code.
        /// </summary>
        /// <param name="encryptContent">encrypt content string.</param>
        /// <returns>result</returns>
        public static string Encrypt(string encryptContent)
        {
            return Encrypt(Encoding.UTF8.GetBytes(encryptContent));
        }

        /// <summary>
        /// MD5 encrypt, end convert byte to base64 code.
        /// </summary>
        /// <param name="encryptContent">encrypt content byte.</param>
        /// <returns>result</returns>
        public static string Encrypt(byte[] encryptContent)
        {
            System.Security.Cryptography.MD5 md5 = new MD5CryptoServiceProvider();
            return Convert.ToBase64String(md5.ComputeHash(encryptContent));
        }
    }
}